package com.jeff.tianti.cms.dao;

import com.jeff.tianti.common.dao.CustomBaseSqlDaoImpl;
import com.jeff.tianti.common.entity.PageModel;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.jeff.tianti.cms.entity.Association;
import com.jeff.tianti.cms.dto.AssociationQueryDTO;
import org.apache.commons.lang3.StringUtils;

/**
 * @author NOW_GO
 * @desc AssociationDaoImpl类 
 * @date 2019-07-12
 */

public class AssociationDaoImpl extends CustomBaseSqlDaoImpl implements AssociationDaoCustom  {

    public PageModel<Association> queryAssociationPage(AssociationQueryDTO associationQueryDTO){
         Map<String,Object> map = new HashMap<String,Object>();
         StringBuilder hql = new StringBuilder();
         hql.append("select t from Association t where t.deleteFlag = 0 ");
        if (associationQueryDTO != null) {
            String name = associationQueryDTO.getName();
            if (StringUtils.isNotBlank(name)) {
                hql.append(" and t.name like :name ");
                map.put("name", "%"+name+"%");
            }
        }
        hql.append(" order by t.sort ");
         return this.queryForPageWithParams(hql.toString(),map,associationQueryDTO.getCurrentPage(),associationQueryDTO.getPageSize());
    }

    public List<Association> queryAssociationList(AssociationQueryDTO associationQueryDTO){
         Map<String,Object> map = new HashMap<String,Object>();
         StringBuilder hql = new StringBuilder();
         hql.append("select t from Association t order by t.sort ");
         return this.queryByMapParams(hql.toString(),map);
    }


}